package com.example.logindemo

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.get_sms.*
import kotlinx.android.synthetic.main.phone_num.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        phoneNumEt.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                changeLoginBtn()
            }

            override fun afterTextChanged(p0: Editable?) {
            }

        })
        getVerificationCodeTv.setOnClickListener {
            Toast.makeText(
                this,
                "快发我验证码！",
                Toast.LENGTH_LONG
            ).show()
        }
    }

    private fun changeLoginBtn() {
        if (phoneNumEt.text.length >= 11) {
            getVerificationCodeTv.setBackgroundResource(R.drawable.shape_btn_bg_enabled)
        } else {
            getVerificationCodeTv.setBackgroundResource(R.drawable.shape_btn_bg_disabled)
        }
    }
}